package com.mall.seckill.mq;

import com.alibaba.fastjson.JSON;
import com.mall.seckill.service.ISeckillGoodsService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Darren
 * @date 2022-10-18 14:06
 * Description：
 */
@Component
@RocketMQMessageListener(
        topic = "order-queue",
        consumerGroup = "orderqueue-consumer",
        selectorExpression = "*"
)
public class OrderQueueListener implements RocketMQListener<Map> {
    @Autowired
    private ISeckillGoodsService seckillGoodsService;

    @Override
    public void onMessage(Map map) {
        System.out.println("排队信息:" + map);
        int count = seckillGoodsService.add(JSON.parseObject(map.get("payload").toString(), Map.class));
    }
}
